package com.zhoutao.blog.seven.dao.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhoutao.blog.seven.dao.mapper.CommentMapper;
import com.zhoutao.blog.seven.dao.model.CommentDao;
import com.zhoutao.blog.seven.model.Ref;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class CommonRepository extends ServiceImpl<CommentMapper, CommentDao> {

    /**
     * 查询关联的资源ID
     *
     * @param ref
     * @return
     */
    public List<CommentDao> findByRef(Ref<Long> ref) {
        final LambdaQueryWrapper<CommentDao> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ref.hasId(), CommentDao::getRefId, ref.getRefId())
                .eq(ref.hasType(), CommentDao::getRefType, ref.getRefType());
        wrapper.orderByAsc(CommentDao::getRefType,CommentDao::getRefId);
        return this.baseMapper.selectList(wrapper);
    }

}
